#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 1e5 + 10, INF = 0x3f3f3f3f;

int n, q;
int root[N], c[N], idx;
struct node {
    int ls, rs, cnt;
}t[N * 17 * 18];

int modify(int x, int l, int r, int v)
{
    int p = ++idx;
    (t[p] = t[x]).cnt++;
    if (l == r) return p;
    int mid = (l + r) >> 1;
    if (v <= mid) t[p].ls = modify(t[x].ls, l, mid, v);
    else t[p].rs = modify(t[x].rs, mid + 1, r, v);
    return p;
}

int query(int u, int v, int l, int r, int k)
{
    if (l == r) return l;
    int cnt = t[t[u].ls].cnt - t[t[v].ls].cnt;
    int mid = (l + r) >> 1;
    if (k <= cnt) return query(t[u].ls, t[v].ls, l, mid, k);
    else return query(t[u].rs, t[v].rs, mid + 1, r, k - cnt);
}

void solve()
{
    cin >> n >> q;
    for (int i = 1;i <= n;i++) {
        int x, flag = 0; cin >> x;
        c[i] = c[i - 1];
        while (1) {
            if (flag == 0) {
                root[i] = modify(root[i - 1], 0, 1e5, x);
                flag = 1;
            } else root[i] = modify(root[i], 0, 1e5, x);
            c[i]++;
            if (x == 0) break;
            x /= 2;
        }
    }

    while (q--) {
        int l, r, k;
        cin >> l >> r >> k;
        if (c[r] - c[l - 1] < k) cout << 0 << '\n';
        else cout << query(root[r], root[l - 1], 0, 1e5, c[r] - c[l - 1] - k) << '\n';
    }
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}